<template>
	<view class="tn-safe-area-inset-bottom">
		<!-- 顶部自定义导航 -->
		<tn-nav-bar fixed alpha customBack>
			<view slot="back" class='tn-custom-nav-bar__back' @click="goBack">
				<text class='icon tn-icon-left'></text>
				<text class='icon tn-icon-home-capsule-fill'></text>
			</view>
		</tn-nav-bar>

		<view class="tn-search-fixed" style="background: linear-gradient(180deg, #D8E5FF, #FFFFFF);">
			<view class="tn-flex tn-flex-row-between tn-flex-col-center tn-margin"
				:style="{paddingTop: vuex_custom_bar_height + 'px'}">

				<view class="justify-content-item align-content-item" style="width: 100vw;">
					<view class="tn-flex tn-flex-col-center"
						style="border: 1rpx solid #3668fc;border-radius: 100rpx;padding: 10rpx 20rpx 10rpx 20rpx;width: 90%;">
						<text class="tn-icon-search justify-content-item tn-padding-right-xs tn-color-gray tn-text-lg"></text>
						<input class="justify-content-item" :value="searchWhere.title" placeholder="想搜点什么咧" @input="inputSearch"
							confirm-type="search" name="input" placeholder-style="color:#AAAAAA" style="width: 90%;"></input>
						<view @click="clearInput">
							<text class="tn-icon-close justify-content-item tn-padding-right-xs tn-color-gray tn-text-lg"
								v-if="searchWhere.title != ''"></text>
						</view>
					</view>
				</view>

				<view class="align-content-item">
					<view class="justify-content-item tn-text-center">
						<tn-button backgroundColor="#3668fc" shape="round" padding="20rpx 20rpx" width="150rpx"
							@click="searchCollection">
							<text class="tn-color-white">搜 索</text>
						</tn-button>

					</view>
				</view>
			</view>
		</view>

		<view class="" style="margin-top: 160rpx;" :style="{paddingTop: vuex_custom_bar_height + 'px'}">
			<view class="tn-flex tn-flex-row-between tn-margin">
				<view class="justify-content-item">
					<text class="tn-text-df tn-color-black"></text>
				</view>
				<view class="justify-content-item tn-text-df tn-color-grey" @click="clearQueryWhere">
					<text class="tn-padding-xs">清除搜索条件</text>
					<text class="tn-icon-delete"></text>
				</view>
			</view>
		</view>

		<view class="">
			<view class="tn-tag-search tn-margin tn-text-justify">
				<!-- 分类搜索结束 -->
				<picker @change="selectCategoryCollection" :value="index" :range="categoryList">
					<view class="tn-flex tn-flex-row-between tn-strip-bottom-min tn-padding" style="padding-left: 0rpx !important;">
						<view class="justify-content-item">
							<view class="tn-text-bold tn-text-lg">
								试题分类
							</view>
							<view class="tn-color-gray tn-padding-top-xs">
								<view class="tn-color-gray">{{categoryList[index]}}</view>
							</view>
						</view>
						<view class="justify-content-item tn-text-lg tn-color-grey  tn-padding-top-xs">
							<view class="tn-icon-right"></view>
						</view>
					</view>
				</picker>
				<!-- 分类搜索开始 -->
			</view>
		</view>

		<view class="tn-flex tn-flex-row-between tn-padding-top-xl tn-margin tn-padding-bottom">
			<view class="justify-content-item tn-text-bold">
				<text class="tn-text-df tn-color-black">搜索结果</text>
			</view>
			<!-- <view class="justify-content-item tn-text-df tn-color-grey">
        <text class="tn-padding-xs">筛选</text>
        <text class="tn-icon-filter"></text>
      </view> -->
		</view>


		<!-- 不建议写时间，因为写了时间，你就要经常更新文章了鸭-->
		<view class="tn-padding-bottom-xl">
			<block v-for="(item, index) in collectionList" :key="index">
				<view class="article-shadow tn-margin" @click="tn('/subpages/exam/collection/detail?uid='+ item.uid)">
					<view class="tn-flex">

						<view class="tn-margin-sm tn-padding-top-xs" style="width: 100%;">
							<view class="tn-text-lg tn-text-bold clamp-text-1 tn-text-justify">
								<text class="">{{ item.title }}</text>
							</view>
							<view class="tn-padding-top-xs" style="min-height: 90rpx;">
								<text class="tn-text-df tn-color-gray clamp-text-2 tn-text-justify">
									<!-- {{ item.remark }} -->
								</text>
							</view>
							<view class="tn-flex tn-flex-row-between tn-flex-col-between tn-margin-top-xs">
								<view class="justify-content-item tn-tag-content__item tn-margin-right tn-text-sm tn-text-bold">
									<text class="tn-tag-content__item--prefix">#</text> {{ item.category.title }}
								</view>
								<view class="justify-content-item tn-color-gray tn-text-center tn-color-gray"
									style="padding-top: 5rpx;">
									<text class="tn-icon-write tn-padding-right-xs tn-text-lg tn-color-gray"></text>
									<text class="tn-padding-right tn-text-df">{{ item.submit }}</text>
									<text class="tn-icon-like-lack tn-padding-right-xs tn-text-lg tn-color-gray"></text>
									<text class="tn-text-df">{{ item.collect }}</text>
								</view>
							</view>
						</view>
						<view class="image-pic tn-margin-sm" :style="'background-image:url(' + item.url + item.path + ')'">
							<view class="image-article">
							</view>
						</view>
					</view>
				</view>
			</block>
			<!-- 内容为空开始 -->
			<view class="" v-if="collectionList.length==0">
				<view class="" style="padding: 7vh 20rpx;">
					<view class="tn-text-center" style="font-size: 200rpx;padding-top: 30rpx;">
						<text class="tn-icon-empty-page tn-color-gray--light"></text>
					</view>
					<view class="tn-color-gray--disabled tn-text-center tn-text-lg">暂无搜索到对应的试题</view>
				</view>
			</view>
			<!-- 内容为空结束 -->
		</view>


	</view>
</template>

<script>
	import template_page_mixin from '@/libs/mixin/template_page_mixin.js'
	import {
		getExamCategList,
		getCollectionList
	} from "@/utils/api/exam.js"
	export default {
		name: 'TemplateSearch',
		mixins: [template_page_mixin],
		data() {
			return {
				inputValue: '',
				cateList: [],
				collectionList: [], // 试卷列表
				searchWhere: { // 查询条件
					category_uid: "",
					page: 1,
					size: 20,
					title: '',
				},
				index: 0,
				categoryList: [],
				show: false,
				list: [{
						value: '1',
						label: 'A'
					},
					{
						value: '2',
						label: 'B'
					},
					{
						value: '3',
						label: 'C'
					}
				],
			}
		},
		onLoad() {
			this.getExamCategList()
			this.getCollectionList()
		},
		methods: {
			// 试题分类选择
			selectCategoryCollection: function(e) {
				this.searchWhere.category_uid = this.cateList[e.detail.value].uid
				this.searchWhere.page = 1
				this.searchWhere.size = 20
				this.collectionList = []
				this.getCollectionList()
			},
			// 试卷分类
			getExamCategList() {
				getExamCategList({}).then(res => {
					if (res.code == 100) {
						this.cateList = res.data
						for (let i = 0; i < res.data.length; i++) {
							this.categoryList[i] = res.data[i].title
						}
						return
					}
					this.$func.showToast(res.msg)
				})
			},
			// 获取试卷列表
			getCollectionList(type = 1) {
				if (type == 2) {
					this.collectionList = []
					this.searchWhere.page = 1
				}
				getCollectionList(this.searchWhere).then(res => {
					if (res.code == 100) {
						this.collectionList.push(...res.data.items)
						this.searchWhere.page = res.data.page + 1
						return
					}
					this.$func.showToast(res.msg)
				})
			},
			// 监听搜索的内容
			inputSearch(e) {
				this.searchWhere.title = e.detail.value
			},
			// 清除搜索内容
			clearInput() {
				this.searchWhere.title = ""
				this.getCollectionList(2)
			},
			// 清楚查询条件
			clearQueryWhere() {
				this.searchWhere.category_uid = ""
				this.searchWhere.page = 1
				this.searchWhere.size = 20
				this.collectionList = []
				this.getCollectionList()
			},
			// 监听搜索按钮
			searchCollection() {
				this.getCollectionList(2)
			},
			// 跳转
			tn(e) {
				uni.navigateTo({
					url: e,
				});
			},
		},
		onReachBottom() {
			this.getCollectionList()
		},
	}
</script>

<style lang="scss" scoped>
	/* 胶囊*/
	.tn-custom-nav-bar__back {
		width: 100%;
		height: 100%;
		position: relative;
		display: flex;
		justify-content: space-evenly;
		align-items: center;
		box-sizing: border-box;
		background-color: rgba(0, 0, 0, 0.15);
		border-radius: 1000rpx;
		border: 1rpx solid rgba(255, 255, 255, 0.5);
		color: #FFFFFF;
		font-size: 18px;

		.icon {
			display: block;
			flex: 1;
			margin: auto;
			text-align: center;
		}

		&:before {
			content: " ";
			width: 1rpx;
			height: 110%;
			position: absolute;
			top: 22.5%;
			left: 0;
			right: 0;
			margin: auto;
			transform: scale(0.5);
			transform-origin: 0 0;
			pointer-events: none;
			box-sizing: border-box;
			opacity: 0.7;
			background-color: #FFFFFF;
		}
	}

	.tn-search-fixed {
		position: fixed;
		top: 0rpx;
		width: 100%;
		transition: all 0.25s ease-out;
		z-index: 1;
	}


	/* 搜索标签 start*/
	.tn-tag-search {
		&__item {
			display: inline-block;
			line-height: 45rpx;
			padding: 10rpx 30rpx;
			margin: 20rpx 20rpx 5rpx 0rpx;

			&--prefix {
				padding-right: 10rpx;
			}
		}
	}

	/* 标签内容 end*/

	/* 标题 start */
	.nav_title {
		-webkit-background-clip: text;
		color: transparent;

		&--wrap {
			position: relative;
			display: flex;
			height: 120rpx;
			font-size: 42rpx;
			align-items: center;
			justify-content: center;
			font-weight: bold;
			background-image: url(https://tnuiimage.tnkjapp.com/title_bg/title00.png);
			background-size: cover;
		}
	}

	/* 标题 end */

	/* 富文本图示意 start */
	.news-img {
		z-index: -1;
		padding-bottom: 40rpx;

		image {
			width: 100%;
			margin: 20rpx 0;
			// height: 3373rpx;
			// z-index: -1;
		}
	}

	/* 资讯主图 start*/
	.image-article {
		border-radius: 8rpx;
		border: 1rpx solid #F8F7F8;
		width: 200rpx;
		height: 200rpx;
		position: relative;
	}

	.image-pic {
		background-size: cover;
		background-repeat: no-repeat;
		// background-attachment:fixed;
		background-position: top;
		border-radius: 10rpx;
	}

	.article-shadow {
		border-radius: 15rpx;
		box-shadow: 0rpx 0rpx 50rpx 0rpx rgba(0, 0, 0, 0.07);
	}

	/* 文字截取*/
	.clamp-text-1 {
		-webkit-line-clamp: 1;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		text-overflow: ellipsis;
		overflow: hidden;
	}

	.clamp-text-2 {
		-webkit-line-clamp: 2;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		text-overflow: ellipsis;
		overflow: hidden;
	}

	/* 标签内容 start*/
	.tn-tag-content {
		&__item {
			display: inline-block;
			line-height: 35rpx;
			color: #1D2541;
			background-color: #F3F2F7;
			border-radius: 10rpx;
			font-size: 22rpx;
			padding: 5rpx 15rpx;

			&--prefix {
				padding-right: 10rpx;
			}
		}
	}
</style>